package com.bankcomm.ui.specialwidget;

import android.app.Activity;
import android.content.Context;
import android.view.MotionEvent;

import com.bankcomm.common.LPMid;
import com.bankcomm.ui.BaseViewCopy;
import com.rytong.tools.ui.Component;
import com.rytong.tools.ui.CssStyle;
import com.rytong.tools.ui.LPHtmlText;
import com.rytong.tools.ui.LPLayout;
import com.rytong.tools.ui.LPScrollView;
import com.rytong.tools.ui.LPLayout.MyLPLayout;
import com.rytong.tools.utils.Utils;

/**
 * 超链接。
 */
public class LPHyperLink extends LPHtmlText {
	
	public class MyLPHypeLink extends MyLPHtmlText{

		public MyLPHypeLink(Context context, String text) {
			super(context, text);
		}
		
		@Override
        public Component composited() {
            return LPHyperLink.this;
        }

		@Override
		public boolean onTouchEvent(MotionEvent event) {
			// TODO Auto-generated method stub
            int touchEvent = event.getAction();
            boolean isAction = false;
            switch (touchEvent) {
            case MotionEvent.ACTION_DOWN:
            	// 按下tr时候变色。
            	trDownColor(tr_, llvSV_);
                yDown_ = event.getY();
                isAction = true;
                this.requestFocus();
                break;
            case MotionEvent.ACTION_MOVE:
            	// 移动tr恢复颜色。
            	int offset = (int) Math.abs(yDown_ - event.getY());
            	if (offset > offset_) {
            		trMoveColor(tr_, llvSV_);
            	}
                moveY(yDown_, event.getY());
                break;
            case MotionEvent.ACTION_UP:
            	// 抬起tr恢复颜色。
            	trUpColor(tr_, llvSV_);
                // 预防控件出现连击效果
                long currentTime = System.currentTimeMillis();
                long timedifference = currentTime - LASTCLICKTIME;
                if (timedifference < 0) {
                    LASTCLICKTIME = currentTime;
                } else if (timedifference < jetLag_) {
                    LASTCLICKTIME = currentTime;
                    return false;
                } else {
                    LASTCLICKTIME = currentTime;
                }
                isClicked_ = true;

                if ("" != getPropertyByName("onclick")) {
                    onClick((String) composited().property_.get("onclick"));
                } else {
                    isAction = true;
                    LPMid.getInstance().um_.dealWithLink(linkAddr_, (BaseViewCopy) this.getContext());
                }
                break;
            default:
                return super.onTouchEvent(event);
            }
            return isAction;
		}
	}
	
	@Override
    public void initRealView(Activity activity, String value) {
        realView_ = new MyLPHypeLink(activity, value);
    }
}
